package com.candy.control;

import com.candy.bean.LoginInfo;
import com.candy.service.UserManager;
import com.candy.service.impl.UserManagerImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/getUserInfoServlet")
public class GetUserInfoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("服务器处理了你的请求");
        //处理get请求
        //处理请求字符集，解决中文乱码问题
        //控制台如果出现乱码可以添加一段配置：-Dfile.encoding=UTF-8  解决中文乱码问题
//        request.setCharacterEncoding("UTF-8");
//        response.setCharacterEncoding("UTF-8");
//        调用service层进行数据处理
        UserManager userManager=new UserManagerImpl();

        try {
            List<LoginInfo> lb= userManager.getUserInfoes();
            request.getSession().setAttribute("userinfoes",lb);
            request.getRequestDispatcher("WEB-INF/userManger/getUserInfo.jsp").forward(request,response);

        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}
